<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="css/eui.css">
</head>
<body>
<div id="app">
    <h1>员工列表</h1>
    <input type="text" placeholder="姓名" v-model="name">
    <input type="text" placeholder="工资" v-model="salary">
    <input type="text" placeholder="工作" v-model="job">
    <input type="button" value="提交" @click="add()">
    <template>
        <el-table
                :data="arr"
                stripe
                style="width: 100%">
            <el-table-column
                    type="index"
                    label="编号"
                    width="80">
            </el-table-column>
            <el-table-column
                    prop="name"
                    label="名字"
                    width="180">

            </el-table-column>
            <el-table-column
                    prop="salary"
                    label="工资"
                    width="180">
            </el-table-column>
            <el-table-column
                    prop="job"
                    label="工作"
                    width="180">
            </el-table-column>
            <el-table-column label="操作">
                <!--scope 代表每行对应的数据，里面 的index属性代表下标，
                里面的row代表每行对应的数组中的对象-->
                <template slot-scope="scope">
                    <el-button
                            size="mini"
                            type="danger"
                            @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
    </template>


</div>
</body>
<!-- import Vue before Element -->
<script src="js/vue.js"></script>
<!-- import JavaScript -->
<script src="js/eui.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function() {
            return {
                name:"",
                salary:"",
                job:"",
                arr:[{name:"孙悟空",salary:"5000",job:"程序员"},
                    {name:"猪八戒",salary:"3000",job:"销售"},
                    {name:"沙僧",salary:"1000",job:"人事"}]
            }
        },
        methods:{
            add(){
                if (v.name.trim()==""||v.salary.trim()==""||v.job.trim()==""){
                    v.$message.error("输入错误！")
                    return;
                }
                v.arr.push({name:v.name,salary:v.salary,job:v.job})
            },
            handleDelete(index, row) {
                console.log(index,row);
                v.arr.splice(index,1)
            }

        }
    })
</script>
</html>
